define([
	'WebPDF',
	 './PDFDocService'], function(WebPDF) {	
	'use strict';
	WebPDF.controller('PDFDocViewerController', ['$scope',
		function($scope) {					
		}]);


	WebPDF.controller('PDFDocController', ['$scope', 'PDFDocService',
		function($scope, PDFDocService) {
			PDFDocService.getPDFDoc()
				.then(function(data) {				
					$scope.pdfDoc = data;
					WebPDF.DocumentLoadFinished($scope.page);					
				}, function(data) {
					alert(data);
			});

			this.pageViewCreated = _.debounce(function() {
				$scope.layout.update();								
				console.log("reinitialise 1");
			}, 500);	
				
			this.updateLayout = function(){			
				$scope.layout.update();	
			};

			this.getPageView = function(pageIndex) {
				return $scope.layout.getContentPane().children("[pageIndex='"+pageIndex+"']");
			};
		}
	]);

	WebPDF.controller('PDFPageController', ['$scope', 'PDFDocService',
		function($scope, PDFDocService){				
			$scope.loadPage = function() {			
			    console.log("loadPage", $scope.page.pageIndex);		
				PDFDocService.loadPDFPage($scope.page)
				.then(function(data) {
					$scope.page = data;					
				}, function(data) {
					alert(data);
				});		
			};	
		}]);


	WebPDF.controller('LeftPanelController', ['$scope',  
		function($scope){		
			
		}]);

});